
(function ($) {
    "use strict";

    
    //验证input不为空
    var input = $('.validate-input .input100');

    $('.validate-form').on('submit',function(){
        var check = true;

        for(var i=0; i<input.length; i++) {
            if(validate(input[i]) == false){
                showIE9(input[i]);
                showValidate(input[i]);
                
                check=false;
            }
        }

        return check;
    });


    $('.validate-form .input100').each(function(){
        $(this).focus(function(){
           hideValidate(this);
        });
    });

    function validate (input) {
    	var flag = $("input[name=supplierFlag]");
        if($(input).attr('type') == 'email' || $(input).attr('name') == 'email') {
            if($(input).val().trim().match(/^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{1,5}|[0-9]{1,3})(\]?)$/) == null) {
                return false;
            }
        }
        else if($(input).attr('name') == 'supplierCode' && !flag.checked){
        	
        }
        else {
            if($(input).val().trim() == ''){
                return false;
            }
        }
    }

    function showValidate(input) {
        var thisAlert = $(input).parent();

        $(thisAlert).addClass('alert-validate');
    }

    function hideValidate(input) {
        var thisAlert = $(input).parent();

        $(thisAlert).removeClass('alert-validate');
        $(".show-validate").css("color","transparent");
    }
    
    //ie9
    function showIE9(x) {
            if(navigator.appVersion.indexOf("MSIE 9.")!=-1){
                var y = $(x).attr('data-validate');
                $(".show-validate span").text(y);
                $(".show-validate").css("color","red");
                 
          };
    }
     
    

})(jQuery);


//修复IE浏览器placeholder
var JPlaceHolder = {
    //检测
    _check : function(){
        return 'placeholder' in document.createElement('input');
    },
    //初始化
    init : function(){
        if(!this._check()){
            this.fix();
        }
    },
    //修复
    fix : function(){
        jQuery(':input[placeholder]').each(function(index, element) {
            var self = $(this), txt = self.attr('placeholder');
            self.wrap($('<div></div>').css({position:'relative', zoom:'1', border:'none', background:'none', padding:'none', margin:'none'}));
            var pos = self.position(), h = self.outerHeight(true), paddingleft = self.css('padding-left'), marginleft = self.css('margin-left');
            var holder = $('<span></span>').text(txt).css({
                position:'absolute', left:pos.left, top:pos.top, height:h, lineHeight:h+'px', paddingLeft:paddingleft,marginLeft:marginleft, color:'#aaa',float:'left'
                                                        }).appendTo(self.parent());

            self.focusin(function(e) {
                holder.hide();
            }).focusout(function(e) {
                if(!self.val()){
                    holder.show();
                }
            });
            holder.click(function(e) {
                holder.hide();
                self.focus();
            });
        });
    }
};
//执行
jQuery(function(){
    JPlaceHolder.init();    
});

//供应商登陆
q = $('#check-supplier .checkbox').is(':checked');
//console.log(q);
$('#check-supplier .checkbox').click(function () {
    if ($(this).is(':checked') == true) {
        //$('#supplier').css("visibility","visible");
        $('#supplier').css("display","block");
    }else{
        //$('#supplier').css("visibility","hidden");
        $('#supplier').css("display","none");
    }
})



// 主页————————————————————————
$('label.tree-toggler').click(function () {
        var icon = $(this).children(".fa");
          if(icon.hasClass("fa-folder-o")){
            icon.removeClass("fa-folder-o").addClass("fa-folder-open-o");
          }else{
            icon.removeClass("fa-folder-open-o").addClass("fa-folder-o");
          }        
          
        $(this).parent().children('ul.tree').toggle(300,function(){
          $(this).parent().toggleClass("open");
          //$(".tree .nscroller").nanoScroller({ preventPageScrolling: true });
        });
      });

$('.nav-list li a').click(function () {
    $(this).parent().parent().parent().parent().find(".actived-tree").removeClass("actived-tree");
    $(this).addClass("actived-tree");

});

//点击菜单，切换内容面板名称
$(".treeview a").click(function () {
        x = $(this).attr('href');
        //alert(typeof(x));
        if(typeof(x) !=="undefined"){//要加typeof()  
              y = $(this).text();
              $('.another-page').text(y);
              $('.another-page').attr('href',x);
              $('.another-page').parent('li').addClass('selected');
              $('.zhu-page').parent('li').removeClass('selected');
        }
});
//zhuye
$('.zhu-page').click(function () {
    $('.zhu-page').parent('li').addClass('selected');
    $('.another-page').parent('li').removeClass('selected');
});
$('.another-page').click(function () {
    $('.another-page').parent('li').addClass('selected');
    $('.zhu-page').parent('li').removeClass('selected');
})

//通知隐藏
$('.close').click(function () {
  $('.modal').css("display","none");
})
//通知隐藏




if(navigator.appVersion.indexOf("MSIE 6.")!=-1||navigator.appVersion.indexOf("MSIE 7.")!=-1||navigator.appVersion.indexOf("MSIE 8.")!=-1){
  var outdated = document.getElementById("outdated");
  outdated.style.display = "block";
  var btnClose = document.getElementById("btnCloseUpdateBrowser");
 //close button
         btnClose.onmousedown = function() {
                outdated.style.display = 'none';
                 return false;
          };
    };


     
//browser detect end

    //ie9高度
    if(navigator.appVersion.indexOf("MSIE 9.")!=-1){
        h=document.body.clientHeight-60;
        $("#page-content").css("height",h);
    }